package com.atguigu.day14.test09;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author fenge
 */
public class Test09 {
    public static void main(String[] args) {
        User[] u1 = new User[]{new User("jack", "1234"),
                new User("rose", "5678"),
                new User("tom", "0000")};
        System.out.println(Arrays.toString(u1));
        System.out.println("请输入用户名");
        Scanner s = new Scanner(System.in);
        String str = s.next();
        boolean isSearch=false;
        for (int i = 0; i < u1.length; i++) {
            if (str.equals(u1[i].getName())){
                isSearch = true;
                System.out.println("请输入密码");
                String pw = s.next();
                System.out.print("登录结果：");
                if (pw.equals(u1[i].getPassword())){
                    System.out.println("登录成功");
                }else{
                    System.out.println("密码错误");
                }
            }
        }
        if (!isSearch)
            System.out.println("没有该用户");
    }
}

class User {
    private String name;
    private String password;

    public User(String name, String password) {
        this.name = name;
        this.password = password;
    }

    public String getName() {
        return name;
    }

    public String getPassword() {
        return password;
    }

    @Override
    public String toString() {
        return name + '-' + password;
    }
}
